<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/601568 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="507"/>
<h1>06-对象、数组</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>创建时间：</b></td><td><i>2018/4/20 14:17</i></td></tr>
<tr><td><b>更新时间：</b></td><td><i>2020/4/8 10:02</i></td></tr>
<tr><td><b>作者：</b></td><td><i>18081003141@163.com</i></td></tr>
</table>
</div>
<br/>

<div>
<span><div><div><span style="font-size: 18pt;">面向对象</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">类</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">我们善于分类，那么什么是类？</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">类----定义属性和方法</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">对象</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">类的具体实现，继承了类所定义的属性和方法（是一种数据类型）</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-weight: bold;">类是对象的抽象，对象是类的实例</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">面向对象的程序思路</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">从现实世界中客观存在的事物（即对象）出发来构造软件系统，并在系统构造中尽可能运用人类的自然思维方式</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">强调直接以现实世界中的事物为中心来思考问题，认识问题</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">程序 = 算法 + 数据结构</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">数据结构合理，算法简单，反之……</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">js是基于对象的编程语言</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">对象可以定义和描述很复杂的数据，让算法变的简单高效</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><hr/><div><span style="font-size: 12pt; font-weight: bold;">js中的对象？</span></div></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">   js语言中一切皆为对象，比如数字、字符串、数组、Math、Object、函数</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">  <b> js中对象的本质：属性和方法的集合</b>（无序，所以对象没有length属性）</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 16px; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(0, 0, 0); font-family: &quot;Yu Gothic UI&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">用官方一点的语言来解释对象：</span></div><div style="margin: 0px; padding: 0px;"><span style="font-size: 16px; color: black; font-family: &quot;Yu Gothic UI&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">       什么是对象，其实就是一种类型，即引用类型。而对象的值就是引用类型的实例。在 ECMAScript 中引用类型是一种数据结构，用于将数据和功能组织在一起。它也常被称做为类，但 ECMAScript6以前却没有这种东西。虽然 ECMAScript 是一门面向对象的语言，却不具备传统面向对象语言所支持的类等基本结构。</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">    创建对象的方式：</span></div><div><span style="font-size: 12pt;">    1、字面量  var obj = {</span></div><div><span style="font-size: 12pt;">        键值对</span></div><div><span style="font-size: 12pt;">        key:value</span></div><div><span style="font-size: 12pt;">    }</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">    2、通过new运算符 var obj = new Object()</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">对象遍历：</span><span style="font-size: 12pt;">for...in循环（隐式迭代）</span></div><div><span style="font-size: 12pt;">    </span></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt; min-height: 17pt; font-family: consolas; color: #364bc0;">var</span><span style="font-size: 12pt;"> <span style="color: #080808;">obj</span></span><span style="font-size: 12pt; min-height: 17pt; font-family: consolas; color: #577909;">= new</span><span style="font-size: 12pt;"> Object()</span><span style="font-size: 12pt; min-height: 17pt; font-family: consolas; color: #080808;">; // 构造函数</span></div><div><span style="font-size: 12pt; min-height: 17pt; font-family: consolas; color: #080808;">obj.name = &quot;zhangsan&quot;;</span></div><div><span style="font-size: 12pt; min-height: 17pt; font-family: consolas; color: #080808;">obj.age = 18;</span></div><div><span style="font-size: 12pt; min-height: 17pt; font-family: consolas; color: #080808;">obj[&quot;gender&quot;] = &quot;male&quot;;</span></div><div style="min-height: 17pt;"><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #577909;">for</span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">(</span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #364bc0;">var</span><span style="min-height: 17pt; font-size: 12pt;"> key</span><span style="min-height: 17pt; font-size: 12pt;"> </span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #577909;">in</span> <span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">obj){</span></div><div style="min-height: 17pt;"><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #3c7a03;">    console</span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">.log(<span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">key</span>);</span></div><div style="min-height: 17pt;"><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #3c7a03;">    console</span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">.log(<span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">obj[</span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">key</span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">]</span></span><span style="min-height: 17pt; font-size: 12pt; font-family: consolas; color: #080808;">);</span></div><div style="min-height: 17pt;"><span style="min-height: 17pt; font-family: consolas; color: #080808; font-size: 12pt;">}</span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16pt;">数组 Array</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">上学时，班上的同学会进行分组，如下图，一竖排是一组</span></div><div><br clear="none"/></div><div>                                     <img src="00-笔记_files/分组.jpg" type="image/jpeg" data-filename="分组.jpg"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">一列就是一个数组，一个数组里面有很多个元素（多个同学）</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt; color: rgb(54, 101, 238);">数组：一组数据（一个变量来承载）</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">var str = &quot;Hello world&quot;; // 一个变量存放一个数据</span></div><div><br clear="none" style="font-family: Monaco; font-size: 9pt; color: #333333;"/></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">var arr = [1,2,3,4,5,6,7,8,9];</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">//往数组结尾插入元素</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">arr[arr.length] = 20</span></div></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">数组有两种定义方式</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt;">var arr = [];</span></div><div><span style="font-size: 12pt;">//字面量的方式</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">var arr = new Array();</span></div><div><span style="font-size: 12pt;">//构造函数的方式</span></div><div><span style="font-size: 12pt;">var arr = new Array(10);//一个参数指数组长度为10</span></div><div><span style="font-size: 12pt;">var arr = new Array(10，20，30);//多个参数指定义数组元素</span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt;"><span style="font-size: 14pt; text-decoration: underline;">因为js是弱类型语言，所以数组也是弱类型，同一个数组变量里可以有各种不同类型的元素</span></span></div><div><br clear="none"/></div><div><span style="font-size: 14pt;">数组的长度</span><span style="font-size: 14pt;">    arr.length</span></div><div><span style="font-size: 14pt;">数组的索引（下标）</span><span style="font-size: 14pt;">    arr[0]  ~ arr[arr.length-1]</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16px;">数组遍历 （for循环）</span></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt; color: #000000;"><span style="min-height: 20pt; font-family: Consolas;">var</span> <span style="min-height: 20pt; font-family: Consolas;">arr</span> <span style="min-height: 20pt; font-family: Consolas;">= [</span><span style="min-height: 20pt; font-family: Consolas;">9</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">2</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">35</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">5</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">74</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">12</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">43</span><span style="min-height: 20pt; font-family: Consolas;">,</span><span style="min-height: 20pt; font-family: Consolas;">4]</span><span style="min-height: 20pt; font-family: Consolas;">;</span></span></div><div style="min-height: 20pt;"><span style="font-size: 12pt; color: #000000;"><span style="min-height: 20pt; font-family: Consolas;">for</span><span style="min-height: 20pt; font-family: Consolas;">(</span><span style="min-height: 20pt; font-family: Consolas;">var</span> <span style="min-height: 20pt; font-family: Consolas;">i</span> <span style="min-height: 20pt; font-family: Consolas;">=</span> <span style="min-height: 20pt; font-family: Consolas;">0</span><span style="min-height: 20pt; font-family: Consolas;">; i</span> <span style="min-height: 20pt; font-family: Consolas;">&lt;</span> <span style="min-height: 20pt; font-family: Consolas;">arr.length; i</span><span style="min-height: 20pt; font-family: Consolas;">++</span><span style="min-height: 20pt; font-family: Consolas;">){</span></span></div><div style="min-height: 20pt;"><span style="font-size: 12pt; color: #000000;"><span style="min-height: 20pt; font-family: Consolas;">    console</span><span style="min-height: 20pt; font-family: Consolas;">.log(arr[i]);</span></span></div><div><span style="min-height: 20pt; font-family: Consolas;"><span style="font-size: 12pt; color: #000000;">}</span></span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">for...in（ES5）  <span style="font-size: 12pt; color: rgb(227, 0, 0);">遍历稀疏数组的时候不会遍历到undefined</span></span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">稀疏数组：即元素稀疏，有些元素没有值的数组，如 [2,undefined,4,5,,6]</span></div><div><br/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt;"><span style="color: #000000; min-height: 20pt; font-family: Consolas;">var</span> <span style="color: #000000; min-height: 20pt; font-family: Consolas;">arr</span> <span style="color: #000000; min-height: 20pt; font-family: Consolas;">= [</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">9</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">2</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">35</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">5</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">74</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">12</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">43</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">,</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">4]</span><span style="color: #000000; min-height: 20pt; font-family: Consolas;">;</span></span></div><div style="min-height: 20pt;"><span style="font-size: 12pt;"><span style="min-height: 20pt; color: #000000; font-family: Consolas;">for</span><span style="min-height: 20pt; color: #000000; font-family: Consolas;">(</span><span style="min-height: 20pt; color: #000000; font-family: Consolas;">var</span><span style="min-height: 20pt; color: #000000; font-family: Monaco;"> key</span><span style="min-height: 20pt; color: #000000; font-family: Consolas;"> in</span><span style="min-height: 20pt; color: #000000; font-family: Monaco;"> </span><span style="min-height: 20pt; color: #000000; font-family: Consolas;">arr</span><span style="min-height: 20pt; color: #000000; font-family: Consolas;">){</span></span></div><div style="min-height: 20pt;"><div><span style="min-height: 20pt; font-family: Consolas;"><span style="font-size: 12pt;"><span style="color: #000000;">    console.log(typeof key);</span> <span style="color: #797979;">//string</span></span></span></div></div><div style="min-height: 20pt;"><span style="font-size: 12pt;"><span style="min-height: 20pt; color: #000000; font-family: Consolas;">    console</span><span style="min-height: 20pt; color: #000000; font-family: Consolas;">.log(arr[key]);</span></span></div><div><span style="min-height: 20pt; font-family: Consolas; color: #000000;"><span style="font-size: 12pt;">}</span></span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">for...of（ES6）</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt; font-family: Consolas;"><span style="color: #000000; min-height: 20pt;">var</span> <span style="color: #000000; min-height: 20pt;">arr</span> <span style="color: #000000; min-height: 20pt;">= [</span><span style="color: #000000; min-height: 20pt;">9</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">2</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">35</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">5</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">74</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">12</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">43</span><span style="color: #000000; min-height: 20pt;">,</span><span style="color: #000000; min-height: 20pt;">4]</span><span style="color: #000000; min-height: 20pt;">;</span></span></div><div style="min-height: 20pt;"><span style="font-size: 12pt; font-family: Consolas;"><span style="min-height: 20pt; color: #000000;">for</span><span style="min-height: 20pt; color: #000000;">(</span><span style="min-height: 20pt; color: #000000;">var</span><span style="min-height: 20pt; color: #000000;"> value </span><span style="min-height: 20pt; color: #000000;">of </span><span style="min-height: 20pt; color: #000000;">arr</span><span style="min-height: 20pt; color: #000000;">){</span></span></div><div style="min-height: 20pt;"><span style="font-size: 12pt; font-family: Consolas;"><span style="min-height: 20pt; color: #000000;">    console</span><span style="min-height: 20pt; color: #000000;">.log(value);</span></span></div><div><span style="min-height: 20pt; color: #000000;"><span style="font-size: 12pt; font-family: Consolas;">}</span></span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">数组是引用类型</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt;">var str = &quot;Hello World&quot;;</span></div><div><span style="font-size: 12pt;">var str2 = str;//内存开辟另外一段空间存放str2</span></div><div><br clear="none"/></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">var arr = [1,2,3,4,5,6,7,8,9];</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">var arr2 = arr;//arr和arr2指向同一段存储空间</span></span></div></div><div><br clear="none"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">基本数据类型：number、string、boolean、undefined、null</span></div><div><span style="font-size: 12pt;">引用数据类型：object（array也属于object）、function</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt; text-indent: 0pt; color: rgb(1, 1, 1);">函数的值传递和引用传递</span></div><div><span style="font-size: 14pt; text-indent: 0pt; color: rgb(1, 1, 1);">基本类型作为参数传递的是指，而引用累心作为参数传递的是引用，即地址</span></div><div><br clear="none"/></div><div><img src="00-笔记_files/钥匙.jpg" type="image/jpeg" data-filename="钥匙.jpg" style="font-size: 12pt; color: #010101;" width="447"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16px;">数组常见API（concat\join\reverse\slice\splice\toString\sort）</span></div><table style="border-collapse: collapse; min-width: 100%;"><colgroup><col style="width: 230px;"></col><col style="width: 469px;"></col></colgroup><tbody><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div style="text-align: center;"><span style="font-weight: bold;">方法</span></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div style="text-align: center;"><span style="font-weight: bold;">描述</span></div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>concat()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>连接两个或更多的数组，并返回结果。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>join()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>把数组的所有元素放入一个字符串。元素通过指定的分隔符进行分隔。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>pop()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>删除并返回数组的最后一个元素</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>push()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>向数组的末尾添加一个或更多元素，并返回新的长度。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>shift()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>删除并返回数组的第一个元素</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>unshift()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>向数组的开头添加一个或更多元素，并返回新的长度。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>reverse()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>颠倒数组中元素的顺序。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>slice()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>从某个已有的数组返回选定的元素</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>sort()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>对数组的元素进行排序</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>splice()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>删除元素，并向数组添加新元素。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 230px; padding: 8px;"><div>toString()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 469px; padding: 8px;"><div>把数组转换为字符串，并返回结果。</div></td></tr></tbody></table><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt;"><span style="font-size: 14pt; font-weight: bold;">练习</span></span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">1、定义一个30项的数组， 按顺序分别赋予从2开始的偶数；在每间隔 5个数 之后，求出前五个数的平均值；</span></div><div><span style="font-size: 12pt;"><br/></span></div><div><span style="font-size: 12pt;"><span style="font-size: 12pt;">2、</span></span><span style="font-size: 12pt; text-indent: 0pt; line-height: 150%;">有一个数组，先</span><span style="font-size: 12pt; text-indent: 0pt; line-height: 150%;">从小到大排好序，再</span><span style="font-size: 12pt; text-indent: 0pt; line-height: 150%;">输入一个数，要求按规律将它插入数组中。  </span></div><div><span style="font-size: 12pt; text-indent: 0pt;"><br/></span></div><div><span style="font-size: 12pt;"><span style="text-indent: 0pt; font-size: 12pt;"><span style="font-size: 12pt; line-height: 150%;">3、</span></span></span><span style="min-height: 20pt; font-size: 12pt; font-family: Consolas;">定义一个含有11个元素的数组  计算下标为奇数的元素的平均数（自定义函数实现）</span></div><div><br clear="none"/></div><div><span style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; min-height: 20pt; font-size: 12pt;"><span style="text-indent: 0pt; font-size: 12pt; color: rgb(1, 1, 1); font-family: Consolas;">4、</span></span><span style="text-indent: 0pt; font-size: 12pt; color: rgb(1, 1, 1);">编写函数map(arr) 把数组中的每一位数字都增加30%</span></div><div><br clear="none"/></div><div><span style="text-indent: 0pt; font-size: 12pt;"><span style="text-indent: 0pt; font-size: 12pt; color: rgb(1, 1, 1);">5、</span></span><span style="text-indent: 0pt; font-size: 12pt; color: rgb(1, 1, 1);">编写函数has(arr , num) 判断数组中是否存在num这个元素，返回布尔类型</span></div><div><span style="text-indent: 0pt; font-size: 12pt;"><br/></span></div><div><span style="text-indent: 0pt; font-size: 12pt; color: rgb(1, 1, 1);">6、</span><span style="font-size: 12pt;">用三种不同的方法做“输入一个数字得到星期几”的作业</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt;"><br/></span></div><div><span style="font-size: 14pt;"><br/></span></div><div><span style="font-size: 14pt;"><br/></span></div><div><br/></div><div><br/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;"> </span><img src="00-笔记_files/双胞胎.jpg" type="image/jpeg" data-filename="双胞胎.jpg" style="font-size: 12pt;" width="327"/>   <img src="00-笔记_files/三胞胎.jpg" type="image/jpeg" data-filename="三胞胎.jpg" style="font-size: 12pt;" width="325"/>    <img src="00-笔记_files/四胞胎.jpg" type="image/jpeg" data-filename="四胞胎.jpg" style="font-size: 12pt;" width="374"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">数组排序？</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 12pt;">冒泡排序</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><img src="00-笔记_files/排序冒泡.gif" type="image/gif" data-filename="排序冒泡.gif" style="font-size: 12pt;"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">选择排序</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><img src="00-笔记_files/排序选择.gif" type="image/gif" data-filename="排序选择.gif" style="font-size: 12pt;"/></div><div><br clear="none" style="font-size: 12pt;"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;"><br/></span></div><div><br clear="none"/></div><div>了解一下排排序的思路</div><div>插入排序</div><div><img src="00-笔记_files/插入排序.gif" type="image/gif" data-filename="插入排序.gif"/></div><div><br clear="none"/></div><div>快速排序</div><div><img src="00-笔记_files/快速排序.gif" type="image/gif" data-filename="快速排序.gif"/></div><div><br/></div><div><br/></div><div><br clear="none"/></div><div><br/></div><div><span style="font-size: 14pt;"><span style="font-size: 14pt; font-weight: bold;">去重</span></span></div><div><span style="font-size: 12pt;">1、双重for循环，只留下不重复的</span></div><div><span style="font-size: 12pt;">2、利用对象属性名不冲突</span></div><div><span style="font-size: 12pt;">3、ES6（Set是一种新的数据类型，加强版数组，默认不允许重复）</span></div><div><font style="font-size: 12pt;"><br/></font></div><div><font style="font-size: 12pt;"><br/></font></div><div><br/></div><div><span style="text-indent: 0pt; font-size: 14pt; color: rgb(1, 1, 1);">JSON是一种数据格式（对象和数组互相嵌套）</span></div><div><br clear="none"/></div><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1); line-height: 150%;">1、使用JSON形式创建一个对象，该对象存储一个学生的信息，该对象包含学号、身份证、年龄、性别、所学专业等属性信息，同时该对象包含一个自我介绍的方法，用来输出该对象的所有信息</span></span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">2、根据json打印表格</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="text-indent: 0pt; font-size: 14pt; color: rgb(1, 1, 1);">ES5新增数组常见方法</span></div><div><br clear="none"/></div><div style="margin: 10px auto; padding: 0px; text-indent: 0px; letter-spacing: normal; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #fefef2;"><span style="text-indent: 0px; letter-spacing: normal; orphans: 2; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 242); font-size: 12pt; color: rgb(0, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal; line-height: 1.5;">2个索引方法：indexOf() 和 lastIndexOf()；</span></div><div style="margin: 10px auto; padding: 0px; text-indent: 0px; letter-spacing: normal; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #fefef2;"><span style="text-indent: 0px; letter-spacing: normal; orphans: 2; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 242); font-size: 12pt; color: rgb(0, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal; line-height: 1.5;">5个迭代方法：forEach()、map()、filter()、some()、every()；</span></div><div><span style="text-indent: 0px; letter-spacing: normal; orphans: 2; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 242); font-size: 12pt; color: rgb(0, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal; line-height: 1.5;">2个归并方法：reduce()、reduceRight()；</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16px; color: rgb(1, 1, 1);">1、二维数组归并为一维数组</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">2、</span><span style="font-size: 12pt;">计算一个二维数字数组所有元素的和</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">3、</span><span style="font-size: 12pt;">把稀疏数组变为不稀疏数组并如下图输出</span></div><div><img src="00-笔记_files/稀疏数组.png" type="image/png" data-filename="稀疏数组.png" style="font-size: 12pt;"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt;"><br/></span></div><div><span style="font-size: 14pt;">附加题：</span></div><div><br/></div><div><span style="font-size: 12pt;">通过循环按行顺序为一个5×5的二维数组a赋1到25的自然数，然后输出该数组的左下半三角。试编程；</span></div><div><img src="00-笔记_files/二维.png" type="image/png" data-filename="二维.png" style="font-size: 12pt;"/></div><div><br clear="none"/></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div></span>
</div></body></html> 